<?php

/**
 * This is the model class for table "empleados".
 *
 * The followings are the available columns in table 'empleados':
 * @property string $IDEmpleado
 * @property string $NOMBRE
 * @property string $APELLIDO
 * @property string $EMAIL
 * @property string $DIRECCION
 * @property string $TELEFONO
 * @property integer $Estado
 *
 * The followings are the available model relations:
 * @property Productos[] $productoses
 */
class Empleados extends CActiveRecord
{
	public $TIPO;
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Empleados the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'empleados';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('IDEmpleado, NOMBRE, APELLIDO, DIRECCION, Estado, TIPO', 'required'),
			array('Estado, TELEFONO', 'numerical', 'integerOnly'=>true),
			array('TELEFONO', 'length', 'min'=>8),
			array('IDEmpleado', 'length', 'min'=>10),
			array('IDEmpleado', 'unique'),
			array('EMAIL','email'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('IDEmpleado, NOMBRE, APELLIDO, EMAIL, DIRECCION, TELEFONO, Estado', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'productoses' => array(self::HAS_MANY, 'Productos', 'IDEmpleado'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'IDEmpleado' => 'Cédula',
			'NOMBRE' => 'Nombre',
			'APELLIDO' => 'Apellido',
			'EMAIL' => 'Email',
			'DIRECCION' => 'Dirección',
			'TELEFONO' => 'Teléfono',
			'Estado' => 'Estado',
			'TIPO'=>'Tipo de cédula'

		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('IDEmpleado',$this->IDEmpleado,true);
		$criteria->compare('NOMBRE',$this->NOMBRE,true);
		$criteria->compare('APELLIDO',$this->APELLIDO,true);
		$criteria->compare('EMAIL',$this->EMAIL,true);
		$criteria->compare('DIRECCION',$this->DIRECCION,true);
		$criteria->compare('TELEFONO',$this->TELEFONO,true);
		$criteria->compare('Estado',$this->Estado);
		
		$_SESSION['datos_filtrados'] = new CActiveDataProvider($this, array(
                'criteria'=>$criteria,
                'pagination'=>false,
        ));
		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}